
var app = getApp(),
currentPage = 1;

Page({

  data: {
    vip: 'N',

    // 3.item数据
    image: "../../image/0713head.png",
 
    toView: "",
    loadingHidden: true,
    renderData: []
  },



  bookBC: function (e) {
    var that = this;

    var index = e.currentTarget.dataset.index;
    var item = that.data.renderData[index];

    wx.navigateTo({
      url: '/pages/booking/bc/bcdoctor/index?TID=' + item.TID
    })
  },


  loadDataFromServer: function () {

    var that = this;
    that.changeLoadingStatus(false);
    var url = app.globalData.getBCBookingList;

    app.userlogin();
    var atkey = wx.getStorageSync("AccessToken");
    var User = wx.getStorageSync("User");

    wx.showLoading({
      title: '数据加载中...'
    })

    // --------- 发送凭证 ------------------
    wx.request({
      url: url,
      data: { AccessToken: atkey },
      header: {
        'content-type': 'application/json'
      },

      success: function (res) {

        var list = [];
        for (var i = 0; i < res.data.datum.length; i++) {
          list.push(res.data.datum[i]);
        }

        var toViewId = currentPage % 2 == 0 ? "top-id" : "top-id2"; //需要改变值页面才会重新渲染

        that.setData({
          renderData: list,
          toView: toViewId,
        });
       
        that.changeLoadingStatus(true);
        wx.hideLoading();

      }
    })
  },

  /**
 * 生命周期函数--监听页面加载
 */
  onLoad: function (options) {
    this.loadDataFromServer();
  },

  //加载上一页或者下拉刷新
  refresh: function (e) {
    currentPage = currentPage > 1 ? --currentPage : 1;
    this.loadDataFromServer();
  },

  //加载下一页
  loadMore: function (e) {
    ++currentPage;
    this.loadDataFromServer();
  },

  //改变loading状态
  changeLoadingStatus: function (bool) {
    this.setData({
      loadingHidden: bool
    });
  },

  onReady: function () {
    // 页面渲染完成
    wx.setNavigationBarTitle({
      title: 'B超预约'
    });
  }

})



